import request from '@/utils/request';

/**
 * 分页查询对账管理
 */
export async function pageWriteOff(params) {
  const res = await request.get('/order/writeOff/page', { params });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询对账管理列表
 */
export async function listWriteOff(params) {
  const res = await request.get('/order/writeOff', { params });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 根据id查询对账管理
 */
export async function getWriteOff(id) {
  const res = await request.get('/order/writeOff/' + id);
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加对账管理
 */
export async function addWriteOff(data) {
  const res = await request.post('/order/writeOff', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改对账管理
 */
export async function updateWriteOff(data) {
  const res = await request.put('/order/writeOff', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 状态修改
 */
export async function updateState(data) {
  const res = await request.put('/order/writeOff/updateState', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 收款确认  状态修改
 */
export async function receiveState(data) {
  const res = await request.put('/order/writeOff/receiveState', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除对账管理
 */
export async function removeWriteOff(id) {
  const res = await request.delete('/order/writeOff/' + id);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
